package m.jclecai.com.adapter.holder;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import m.jclecai.com.R;
import m.jclecai.com.bean.reconmend.ReconmentPerson;
import m.jclecai.com.data.Lecai_SDK;
import m.jclecai.com.fragment.RecommendFragment;
import m.jclecai.com.listener.Callback;
import m.jclecai.com.view.rounded.RoundedImageView;

/**
 * Created by ZD on 2017/7/19.
 */

public class RecomPersonHolder extends RecyclerView.ViewHolder {

    private Callback mCallback;
    @BindView(R.id.iv_icon)
    RoundedImageView ivIcon;
    @BindView(R.id.tv_name)
    TextView tvName;
    int mPosition = 0;
    ReconmentPerson rp;

    public RecomPersonHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this, itemView);
    }

    public void init(Callback mCallback, int position, JSONObject obj) {
        this.mCallback = mCallback;
        mPosition = position;
        if (position == 7) {
            ivIcon.setImageResource(R.mipmap.experts_more);
            tvName.setText("更多");
        } else {
            tvName.setText(obj.getString("authName"));
            Glide.with(itemView.getContext()).
                    load(obj.getString("authheadImlUrl")).
                    asBitmap().
                    placeholder(R.drawable.my_head_de).
                    into(ivIcon);
            tvName.setText(obj.getString("authName"));
        }
    }


    public void initData(Callback mCallback, int position, ReconmentPerson person) {
        this.mCallback = mCallback;
        rp = person;
        mPosition = position;
        if (position == 7) {
            ivIcon.setImageResource(R.mipmap.experts_more);
            tvName.setText("更多");
        } else {
            tvName.setText(person.getUsername());
            Glide.with(itemView.getContext()).
                    load(person.getUser_face()).
                    asBitmap().
                    placeholder(R.drawable.my_head_de).
                    into(ivIcon);
//            tvName.setText(person.getNickname());
        }
    }

    @OnClick(R.id.llBody)
    void toRmDetail() {
        if (mCallback != null)
            if (mPosition < 7){
                Lecai_SDK.persion_id = rp.getUser_id();
                mCallback.callback(RecommendFragment.JUMP.RmFamousActivity);
            } else{
                mCallback.callback(RecommendFragment.JUMP.RmListActivity);
            }


    }

}
